package com.example.demo.config;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 类描述: 动态数据源的配置类
 *
 * @author  zhanglei
 * @date 2019/3/8 9:10
 **/
@Component
@ConfigurationProperties(prefix = "database-holder")
@RefreshScope
public class DataBaseHolder {

    private List<DataBaseInfo> databaseList;

    public List<DataBaseInfo> getDatabaseList() {
        return databaseList;
    }

    public void setDatabaseList(List<DataBaseInfo> databaseList) {
        this.databaseList = databaseList;
    }

    public boolean existDatabase(Integer dbID){
        for(DataBaseInfo dataBaseInfo:databaseList){
            if(dataBaseInfo.getDbId().equals(dbID)){
                return true;
            }
        }
        return false;
    }


}
